package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_register_payments;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_register_payments;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_register_paymentsSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_register_paymentsService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[登记付款] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_register_paymentsServiceImpl implements IAccount_register_paymentsService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_register_paymentsClientService account_register_paymentsClientService;

    @Override
    public void updateBatch(List<Account_register_payments> account_register_paymentss, int batchSize) {

        //account_register_paymentsClientService.updateBatch(account_register_paymentss,batchSize) ;

    }

    @Override
    public Account_register_payments get(Integer id) {
        Iaccount_register_payments clientModel = account_register_paymentsClientService.createModel();
        clientModel.setId(id);
        account_register_paymentsClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_register_payments get(Account_register_payments account_register_payments) {
        Account_register_payments retaccount_register_payments = this.get(account_register_payments.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_register_payments.getClass(), account_register_payments.getClass(), false);
        copier.copy(retaccount_register_payments, account_register_payments, null);
        return account_register_payments ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_register_paymentsClientService.removeBatch(account_register_paymentss) ;

    }

    @Override
    public boolean create(Account_register_payments account_register_payments) {
        boolean bOk = false ;
        Iaccount_register_payments clientModel = this.convert2Model(account_register_payments,null);
        account_register_paymentsClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_register_payments);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Account_register_payments account_register_payments) {
        boolean bOk = false ;
        Iaccount_register_payments clientModel = this.convert2Model(account_register_payments,null);
        account_register_paymentsClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_register_payments) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Account_register_payments> account_register_paymentss, int batchSize) {

                        //account_register_paymentsClientService.createBatch(account_register_paymentss,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_register_payments clientModel = account_register_paymentsClientService.createModel();
        clientModel.setId(id);
        account_register_paymentsClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_register_payments> searchDefault(Account_register_paymentsSearchContext context) {
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据科目查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_writeoff_account(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据日记账查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_journal(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据付款方法查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_payment_method(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据币种查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_currency(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据银行账户查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_partner_bank_account(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_partner(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_create(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_register_payments> selectByOdoo_write(Integer id){
        Account_register_paymentsSearchContext context = new Account_register_paymentsSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_register_payments> list = new ArrayList<Account_register_payments>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_register_payments> clientModelList = account_register_paymentsClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_register_payments clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_register_payments>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_register_payments convert2Model(Account_register_payments domain , Iaccount_register_payments model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_register_paymentsClientService.createModel() ;
        }

         if(domain.getShow_communication_fieldDirtyFlag())
            model.setShow_communication_field(domain.getShow_communication_field());
         if(domain.getPayment_typeDirtyFlag())
            model.setPayment_type(domain.getPayment_type());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getPartner_typeDirtyFlag())
            model.setPartner_type(domain.getPartner_type());
         if(domain.getCommunicationDirtyFlag())
            model.setCommunication(domain.getCommunication());
         if(domain.getPayment_differenceDirtyFlag())
            model.setPayment_difference(domain.getPayment_difference());
         if(domain.getShow_partner_bank_accountDirtyFlag())
            model.setShow_partner_bank_account(domain.getShow_partner_bank_account());
         if(domain.getGroup_invoicesDirtyFlag())
            model.setGroup_invoices(domain.getGroup_invoices());
         if(domain.getHide_payment_methodDirtyFlag())
            model.setHide_payment_method(domain.getHide_payment_method());
         if(domain.getInvoice_idsDirtyFlag())
            model.setInvoice_ids(domain.getInvoice_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getPayment_dateDirtyFlag())
            model.setPayment_date(domain.getPayment_date());
         if(domain.getWriteoff_labelDirtyFlag())
            model.setWriteoff_label(domain.getWriteoff_label());
         if(domain.getMultiDirtyFlag())
            model.setMulti(domain.getMulti());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getPayment_difference_handlingDirtyFlag())
            model.setPayment_difference_handling(domain.getPayment_difference_handling());
         if(domain.getAmountDirtyFlag())
            model.setAmount(domain.getAmount());
         if(domain.getCurrency_id_textDirtyFlag())
            model.setCurrency_id_text(domain.getCurrency_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getPayment_method_codeDirtyFlag())
            model.setPayment_method_code(domain.getPayment_method_code());
         if(domain.getPayment_method_id_textDirtyFlag())
            model.setPayment_method_id_text(domain.getPayment_method_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getWriteoff_account_id_textDirtyFlag())
            model.setWriteoff_account_id_text(domain.getWriteoff_account_id_text());
         if(domain.getWriteoff_account_idDirtyFlag())
            model.setWriteoff_account_id(domain.getWriteoff_account_id());
         if(domain.getPartner_bank_account_idDirtyFlag())
            model.setPartner_bank_account_id(domain.getPartner_bank_account_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getPayment_method_idDirtyFlag())
            model.setPayment_method_id(domain.getPayment_method_id());
        return model ;
    }

    public Account_register_payments convert2Domain( Iaccount_register_payments model ,Account_register_payments domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_register_payments();
        }

        if(model.getShow_communication_fieldDirtyFlag())
            domain.setShow_communication_field(model.getShow_communication_field());
        if(model.getPayment_typeDirtyFlag())
            domain.setPayment_type(model.getPayment_type());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getPartner_typeDirtyFlag())
            domain.setPartner_type(model.getPartner_type());
        if(model.getCommunicationDirtyFlag())
            domain.setCommunication(model.getCommunication());
        if(model.getPayment_differenceDirtyFlag())
            domain.setPayment_difference(model.getPayment_difference());
        if(model.getShow_partner_bank_accountDirtyFlag())
            domain.setShow_partner_bank_account(model.getShow_partner_bank_account());
        if(model.getGroup_invoicesDirtyFlag())
            domain.setGroup_invoices(model.getGroup_invoices());
        if(model.getHide_payment_methodDirtyFlag())
            domain.setHide_payment_method(model.getHide_payment_method());
        if(model.getInvoice_idsDirtyFlag())
            domain.setInvoice_ids(model.getInvoice_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getPayment_dateDirtyFlag())
            domain.setPayment_date(model.getPayment_date());
        if(model.getWriteoff_labelDirtyFlag())
            domain.setWriteoff_label(model.getWriteoff_label());
        if(model.getMultiDirtyFlag())
            domain.setMulti(model.getMulti());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getPayment_difference_handlingDirtyFlag())
            domain.setPayment_difference_handling(model.getPayment_difference_handling());
        if(model.getAmountDirtyFlag())
            domain.setAmount(model.getAmount());
        if(model.getCurrency_id_textDirtyFlag())
            domain.setCurrency_id_text(model.getCurrency_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getPayment_method_codeDirtyFlag())
            domain.setPayment_method_code(model.getPayment_method_code());
        if(model.getPayment_method_id_textDirtyFlag())
            domain.setPayment_method_id_text(model.getPayment_method_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getWriteoff_account_id_textDirtyFlag())
            domain.setWriteoff_account_id_text(model.getWriteoff_account_id_text());
        if(model.getWriteoff_account_idDirtyFlag())
            domain.setWriteoff_account_id(model.getWriteoff_account_id());
        if(model.getPartner_bank_account_idDirtyFlag())
            domain.setPartner_bank_account_id(model.getPartner_bank_account_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getPayment_method_idDirtyFlag())
            domain.setPayment_method_id(model.getPayment_method_id());
        return domain ;
    }


}
